package com.demo.juc.volatildemo;

/**
 * @Author: jxm
 * @Description: 测试volatile, 可见性特征
 * @Date: 2022/10/12 14:31
 * @Version: 1.0
 */

class MyData{

    volatile int number = 0;

    public void addTo60(){
        this.number = 60;
    }
}

public class Test01 {

    public static void main(String[] args) {
        MyData myData = new MyData();

        new Thread(()->{
            System.out.println(Thread.currentThread()+"\t com in");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            myData.addTo60();
            System.out.println(Thread.currentThread()+"\t out to");
        },"a").start();

        while (myData.number == 0){
            System.out.println("---------等待---------");
        }

        System.out.println("-------------结束-------------");
    }
}

